package com.iw.sms.quartz;

import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.alvin.sms.model.RecivedSmsVO;
import com.iw.sms.entity.Sms;
import com.iw.sms.entity.SmsState;
import com.iw.sms.entity.SmsType;
import com.iw.sms.service.AlvinSmsService;
import com.iw.sms.service.SmsService;

@Component
public class AutoReciveQuartz {

	public static boolean isRun = false;

	static {
		isRun = SmsConfig.getRun(SmsConfig.AUTO_RECIVE_RUN);
	}

	@Autowired
	private SmsService smsService;

	@Autowired
	private AlvinSmsService alvinSmsService;

	public void run() {
		if (isRun) {
			try {
				List<RecivedSmsVO> list = alvinSmsService.recivedSms();
				if (list != null && list.size() > 0) {
					for (RecivedSmsVO vo : list) {
						Sms sms = new Sms();
						sms.setMobile(vo.getMobile());
						sms.setContent(vo.getContent());
						sms.setMoId(vo.getMoId());
						sms.setSpNumber(vo.getSpNumber());
						sms.setStime(vo.getRtime());
						sms.setMobile(vo.getMobile());
						sms.setMobile(vo.getMobile());
						sms.setType(SmsType.R);
						sms.setState(SmsState.WIL_REPLY);
						sms.setInsertTime(new Date());
						smsService.save(sms);
					}
				}
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
	}

}
